<?php include '../template/template_main.tpl'; 
require("../connect/connect.php");

if(isset($_SESSION['profile']) && !($_SESSION['profile'] == 2))
	header("Location: ../index.php");
	
if (isset($_POST['reg']))
{
	$error = array();
	if ($_POST['reg'] == "")
	{
		$error[] = "O regulamento não pode estar vazio.";
	}
	$file = fopen('../lib/regulamento.txt', 'w');
	fwrite($file, $_POST['reg']);
	$mensagem = "Regulamento actualizado com sucesso.";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../css/template.css" />
<link rel="stylesheet" type="text/css" href="../css/corpo_main.css" />
<script type="text/javascript" src="../js/jquery-1.7.2.js" ></script>
<script type="text/javascript" src="../js/main.js" ></script>

<title>.:MateMatrix:.</title>

</head>
<body>
	<?php makeHeader(); ?>
	<?php
	echo $estruturaInicio;
	$lines = file('../lib/regulamento.txt', FILE_TEXT);
	$regulamento = "";
	foreach ($lines as $line_num => $line) {
    	$regulamento = $regulamento.$line;
	}
	?>
	<div id="title">
		<h1>- Regulamento -</h1>
	</div>
	<?php
		if (isset($error) && (count($error) > 0))
		{
			echo "<div class=\"erros\"><ul>";
			foreach ($error as $value) {
				printf("<li>%s</li>", $value);
			}
			echo "</ul></div>";
		}
		if (isset($mensagem))
		{
			echo "<div class=\"info\"><ul><li>$mensagem</li></ul></div>";
		}
	?>
	
	<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
		<div>
			<label for="reg">Regulamento</label>
		</div>
		<div>
			<textarea id="reg" name="reg" cols="120" rows="25"><?php echo htmlspecialchars($regulamento); ?></textarea>
		</div> 
		<div>
			<input type="submit" name="submit" value="Actualizar" />
		</div>
	</form>
	
	<?php echo $estruturaFim; ?>
	<?php echo $footer;?>
</body>
</html>